<#include "java_copyright.include">
<#assign tableName = table.sqlName>
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<#assign classNameAllUpper = className?upper_case>
package ${basepackage}.${subpackage}.data.dao.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ${basepackage}.base.BaseDAO;
import ${basepackage}.util.DaoUtils;
import ${basepackage}.${subpackage}.data.dao.I${className}DAO;
import ${basepackage}.${subpackage}.data.vo.${className}VO;


/**
 * 
 */
public class ${className}DAOImpl extends BaseDAO implements I${className}DAO {

	protected static Log log = LogFactory.getLog(${className}DAOImpl.class);

	static final String ${classNameAllUpper}_SEQ = "${tableName}_seq";//just for oracle

	static final String TABLE_NAME = "${tableName}"; 
	static final String TABLE_FIELD = "<#list table.columns as column><#if table.columns?last!=column>${column.sqlName} as ${column.columnNameLower},<#else>${column.sqlName} as ${column.columnNameLower}</#if></#list>";
	static final String GETVO_STRING = "select "+TABLE_FIELD+" from ${tableName} WHERE <#list table.columns as column><#if column.pk>${column.sqlName}=?</#if></#list>";	
	static final String INSERT_STRING = "insert into ${tableName}(<#list table.columns as column><#if table.columns?last!=column>${column.sqlName},<#else>${column.sqlName}</#if></#list>) values (<#list table.columns as column><#if table.columns?last!=column>:${column.columnNameLower},<#else>:${column.columnNameLower}</#if></#list>)";
	static final String UPDATE_STRING = "update ${tableName} set <#list table.columns as column><#if !column.pk><#if table.columns?last!=column>${column.sqlName}=:${column.columnNameLower},<#else>${column.sqlName}=:${column.columnNameLower}</#if></#if></#list> where <#list table.columns as column><#if column.pk>${column.sqlName}=:${column.columnNameLower}</#if></#list>";
	static final String DELETE_STRING = "delete from ${tableName} where <#list table.columns as column><#if column.pk>${column.sqlName}=?</#if></#list>";

	@Override
	public ${className}VO get${className}VO(String id) {
		${className}VO ${classNameLower}VO = getVO(GETVO_STRING, id, new ${className}VO());
		return ${classNameLower}VO;
	}
		
	@Override
	public String insert${className}VO(${className}VO ${classNameLower}VO) {  
		if (DB_TYPE.equals(DaoUtils.DBNAME_ORACLE)) {
			${classNameLower}VO.setUserId(getSequenceString(USERS_SEQ));
		}
		String id = insertVO(INSERT_STRING, ${classNameLower}VO);
		log.info("The generated id :" + id);
		return id;
	}
	

	@Override
	public boolean update${className}VO(${className}VO ${classNameLower}VO) {
		return updateVO(UPDATE_STRING, ${classNameLower}VO);
	}
	

	@Override
	public boolean delete${className}VO(String id) {
		return deleteVO(DELETE_STRING, id);
	}
	
	/*--------------The above methods are automatically generated--------------*/
}
